/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.elec.ad.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.elec.ad.entity.ElecAdList;
import cn.net.ecode.elec.ad.service.ElecAdListService;

import java.util.List;

/**
 * 广告项列表Controller
 *
 * @author AlanShelby
 * @version 2019-08-26
 */
@Controller
@RequestMapping(value = "${adminPath}/ad/elecAdList")
public class ElecAdListController extends BaseController {

    @Autowired
    private ElecAdListService elecAdListService;

    /**
     * 获取数据
     */
    @ModelAttribute
    public ElecAdList get(String id, boolean isNewRecord) {
        return elecAdListService.get(id, isNewRecord);
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("ad:elecAd:view")
    @RequestMapping(value = {"list", ""})
    public String list(ElecAdList elecAdList, Model model) {
        model.addAttribute("elecAdList", elecAdList);
        return "elec/ad/elecAdListList";
    }

    /**
     * 查询列表数据
     */
    @RequiresPermissions("ad:elecAd:view")
    @ResponseBody
    @RequestMapping(value = "listData")
    public Page<ElecAdList> listData(ElecAdList elecAdList, HttpServletRequest request, HttpServletResponse response, Model model) {
        Page<ElecAdList> page = elecAdListService.findPage(new Page<ElecAdList>(request, response), elecAdList);
        return page;
    }

    /**
     * 查看编辑表单
     */
    @RequiresPermissions("ad:elecAd:view")
    @RequestMapping(value = "form")
    public String form(ElecAdList elecAdList, Model model) {
        List<ElecAdList> list = elecAdListService.findList(elecAdList);
        model.addAttribute("adList", list);
        return "elec/ad/elecAdListForm";
    }

    /**
     * 保存数据
     */
    @RequiresPermissions("ad:elecAd:edit")
    @ResponseBody
    @RequestMapping(value = "save")
    public String save(ElecAdList elecAdList) {
        StringBuilder message = new StringBuilder();
        if (!beanValidator(message, elecAdList)) {
            return renderResult(Global.FALSE, message);
        }
        elecAdListService.save(elecAdList);
        return renderResult(Global.TRUE, "保存广告项列表成功！");
    }

    /**
     * 删除数据
     */
    @RequiresPermissions("ad:elecAd:edit")
    @ResponseBody
    @RequestMapping(value = "delete")
    public String delete(ElecAdList elecAdList) {
        elecAdListService.delete(elecAdList);
        return renderResult(Global.TRUE, "删除广告项列表成功！");
    }

}